﻿Imports EVOLTA.Promocion.Bl.Bc
Imports EVOLTA.Promocion.Bl.Be

Partial Class promocionVenta
    Inherits System.Web.UI.MasterPage

    Private Evolta As New Eevolta
    Private _mostrarMenu As Boolean
    Private _idUsuario As Int32 = 0                 ' cambiar
    Private _idProyecto As Int32 = 0                ' cambiar
    Private _idEtapa As Int32 = 0                   ' cambiar

    Public WriteOnly Property showMenu() As Boolean
        Set(ByVal value As Boolean)
            mnuPrincipal.Visible = value
        End Set
    End Property
    Public Property mostrarMenu() As Boolean
        Get
            If Session("mostrarMenu") Is Nothing Then
                Return False
            Else
                Return CType(Session("mostrarMenu"), Boolean)
            End If
            'Return _mostrarMenu
        End Get
        Set(ByVal value As Boolean)
            Session("mostrarMenu") = value
            '_mostrarMenu = value
        End Set
    End Property
    Public Property idUsuario() As Int32
        Get
            If Session("idUsuario") Is Nothing Then
                Return 0
            Else
                Return CType(Session("idUsuario"), Int32)
            End If
            'Return _idUsuario
        End Get
        Set(ByVal value As Int32)
            '_idUsuario = value
            Session("idUsuario") = value
        End Set
    End Property
    Public Property descUsuario() As String
        Get
            Return lnkUsuario.Text
        End Get
        Set(ByVal value As String)
            lnkUsuario.Text = value.ToUpper
        End Set
    End Property
    Public Property descEmpresa() As String
        Get
            If Session("descEmpresa") Is Nothing Then
                Return False
            Else
                Return CType(Session("descEmpresa"), String)
            End If
            'Return lblEmpresa.Text.Trim
        End Get
        Set(ByVal value As String)
            Session("descEmpresa") = value
            lblEmpresa.Text = value.ToUpper.Trim
        End Set
    End Property
    Public Property idProyecto() As Int32
        Get
            If Session("idProyecto") Is Nothing Then
                Return 0
            Else
                Return CType(Session("idProyecto"), Int32)
            End If
            'Return _idProyecto
        End Get
        Set(ByVal value As Int32)
            Session("idProyecto") = value
            '_idProyecto = value
        End Set
    End Property
    Public Property descProyecto() As String
        Get
            If Session("descProyecto") Is Nothing Then
                Return ""
            Else
                Return CType(Session("descProyecto"), String)
            End If
        End Get
        Set(ByVal value As String)
            Session("descProyecto") = value
        End Set
    End Property
    Public Property idEtapa() As Int32
        Get
            If Session("idEtapa") Is Nothing Then
                Return 0
            Else
                Return CType(Session("idEtapa"), Int32)
            End If
            'Return _idEtapa
        End Get
        Set(ByVal value As Int32)
            Session("idEtapa") = value
            '_idEtapa = value
        End Set
    End Property
    Public Property descEtapa() As String
        Get
            If Session("descEtapa") Is Nothing Then
                Return ""
            Else
                Return CType(Session("descEtapa"), String)
            End If
        End Get
        Set(ByVal value As String)
            Session("descEtapa") = value
        End Set
    End Property
    Public Property idPerfilUsuario() As Int32
        Get
            If Session("idPerfilUsuario") Is Nothing Then
                Return 0
            Else
                Return CType(Session("idPerfilUsuario"), Int32)
            End If
        End Get
        Set(ByVal value As Int32)
            Session("idPerfilUsuario") = value
        End Set
    End Property
    Public Property sEvolta() As Eevolta
        Get
            Return Session("sEVOLTA")
        End Get
        Set(ByVal value As Eevolta)
            Session("sEVOLTA") = value
        End Set
    End Property

    Public Property MasterlblProyecto() As String
        Get
            Return lblMasterProyecto.Text
        End Get
        Set(ByVal value As String)
            lblMasterProyecto.Text = value
        End Set
    End Property
    Public Property MasterlblEtapa() As String
        Get
            Return lblMasterEtapa.Text
        End Get
        Set(ByVal value As String)
            lblMasterEtapa.Text = value
        End Set
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Page.Header.DataBind()
        cargarSession()
        lblFechaValor.Text = System.DateTime.Now.ToShortDateString
        If Not IsPostBack Then
            'If _mostrarMenu Then mnuModulo(2)
            If mostrarMenu Then mnuModulo(2)
        End If
    End Sub
    'Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
    '    Session("modulo") = Nothing
    '    Session("login") = Nothing
    '    Server.Transfer("~/default.aspx")
    'End Sub
    Private Sub mnuModulo(ByVal vModulo As Int32)
        Dim modulos As List(Of Emodulos) = Rmodulos.SeleccionarTodo(descEmpresa, False, vModulo)
        For Each mnu As Emodulos In modulos
            Dim objMn As New MenuItem
            objMn.Value = mnu.idModulo
            'objMn.Text = mnu.descModulo
            objMn.Text = ""
            mnuPrincipal.Items.Add(objMn)
            mnuSubModulo(objMn, vModulo)
        Next
    End Sub
    Private Sub mnuSubModulo(ByRef mnu As MenuItem, ByVal vModulo As Int32)
        Dim Ruta As String = Session("sRuta")
        Dim submodulos As List(Of EsubModulo) = Rsubmodulos.SeleccionarTodoXModuloProyecto(descEmpresa, False, vModulo, CType(Me.idPerfilUsuario, Int32), Ruta)
        Dim opciones As List(Of Eopciones) = Ropciones.SeleccionarTodoXModuloSubModulo(descEmpresa, vModulo, CType(Me.idPerfilUsuario, Int32))
        For Each submnu As EsubModulo In submodulos
            Dim objMn As New MenuItem
            objMn.Value = submnu.idSubModulo
            objMn.Text = submnu.descSubModulo
            If submnu.direccionUrl.Trim.Length > 0 Then objMn.NavigateUrl = submnu.direccionUrl
            mnu.ChildItems.Add(objMn)
            If Not opciones Is Nothing Then
                mnuOpciones(objMn, opciones, submnu.idSubModulo)
            End If
        Next
    End Sub
    Private Sub mnuOpciones(ByRef mnu As MenuItem, ByVal lstOpc As List(Of Eopciones), ByVal idSubModulo As Int32)
        For Each opc As Eopciones In lstOpc
            If opc.idSubModulo.Equals(idSubModulo) Then
                Dim objMn As New MenuItem
                objMn.Value = opc.idOpcion
                objMn.Text = opc.descOpcion
                objMn.NavigateUrl = ObtenerRuta(opc.direccionUrl) '"~/AdmSist/opciones.aspx" '"URl pag Web"
                mnu.ChildItems.Add(objMn)
            End If
        Next
    End Sub
    Private Function ObtenerRuta(ByVal pagina As String) As String
        Dim ruta As String = Nothing
        'ruta = "~/reportesGestion/" + pagina + ".aspx"
        ruta = pagina
        Return ruta
    End Function
    'Protected Sub lnkUsuario_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkUsuario.Click
    '    'Try
    '    '    Dim ruta As String = ConfigurationManager.AppSettings("cerrar").ToString
    '    '    Response.Redirect(ruta)
    '    'Catch ex As Exception
    '    '    Throw
    '    'End Try
    'End Sub
    Public Sub cargarSession()
        Try
            'Evolta = CType(Session("sEVOLTA"), Eevolta)
            Evolta = CType(Me.sEvolta, Eevolta)
            If Not Evolta Is Nothing Then
                idProyecto = Evolta.idProyecto
                descProyecto = Evolta.descProyecto
                idEtapa = Evolta.idEtapa
                descEtapa = Evolta.descEtapa
                MasterlblProyecto = Convert.ToString(Evolta.descProyecto)
                MasterlblEtapa = Convert.ToString(Evolta.descEtapa)
                descEmpresa = Evolta.descEmpresa
                idUsuario = Evolta.idUsuario
                descUsuario = Evolta.descUsuario.ToUpper
            Else
                Response.Redirect(ConfigurationManager.AppSettings("cerrar").ToString)
            End If
        Catch ex As Exception
            Response.Redirect(ConfigurationManager.AppSettings("cerrar").ToString)
        End Try
    End Sub
    Protected Sub ScriptManager1_AsyncPostBackError(ByVal sender As Object, ByVal e As System.Web.UI.AsyncPostBackErrorEventArgs) Handles ScriptManager1.AsyncPostBackError
        ScriptManager1.AsyncPostBackErrorMessage = "Se ha producido un error en la operación. Si persiste contactese con el Administrator."
    End Sub

End Class